package net.lukecloud.xile.activity;

import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import net.lukecloud.xile.App;
import net.lukecloud.xile.R;
import net.lukecloud.xile.net.ApiService;

import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class DeviceActivity extends AppCompatActivity {
    ApiService apiService;
    long id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device);
        id = getIntent().getLongExtra("id", -1);
        ButterKnife.bind(this);
        apiService = ((App) getApplication()).retrofit.create(ApiService.class);
    }

    @OnClick(R.id.mode_echo)
    public void click_echo(final View view){
        apiService.deviceEcho(id).enqueue(new Callback<Void>() {
            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if(response.isSuccessful()){
                    Snackbar.make(view, "echo ", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }else{

                    Snackbar.make(view, "echo error "+response.message(), Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                Snackbar.make(view, "echo error", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }
    @OnClick(R.id.mode_1)
    public void click_mode_1(){

    }
    @OnClick(R.id.mode_2)
    public void click_mode_2(){

    }
    @OnClick(R.id.mode_3)
    public void click_mode_3(){

    }
    @OnClick(R.id.mode_4)
    public void click_mode_4(){

    }

}
